local skel=fk.CreateSkill{
    name="ym_water__gongnan",
    tgas={Skill.Compulsory},
}
Fk:loadTranslationTable{
    ["ym_water__gongnan"]="攻南",
    
    [":ym_water__gongnan"]="你可以将至少一张牌置于牌堆顶，以视为使用【兵临城下】。若没有【杀】被使用，你获得展示的其余牌，否则此技能失效。",
    ["#ym_water__gongnan-viewas"]="攻南：将至少一张牌置于牌堆顶，以视为使用【兵临城下】",
}

skel:addEffect("viewas",{
  anim_type = "offensive",
  pattern = "emo__enemy_at_the_gates",
  prompt = "#ym_water__gongnan-viewas",
  card_filter = function(self, player, to_select, selected)
    return true
  end,
  view_as = function(self, player, cards)
    if #cards == 0 then return end

    local c = Fk:cloneCard("emo__enemy_at_the_gates")
    c.skillName = skel.name
    c:addFakeSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    if #use.card.fake_subcards == 0 then return end
    room:moveCards({
        ids = use.card.fake_subcards,
        from = player,
        fromArea = Card.PlayerHand,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = skel.name,
      })
   
  end,
  after_use = function(self, player, use)
    local room = player.room
    if not (use and use.extra_data and use.extra_data.enemy_at_the_gates_Info and #use.extra_data.enemy_at_the_gates_Info > 0) then
       
        local cards=use.extra_data.rest or {}
        if #cards > 0 then
           local get={}
           for _,id in ipairs(cards) do
            if not table.contains(use.card.fake_subcards,id) then
                table.insert(get,id)
            end
           end
           room:obtainCard(player,get,true,fk.ReasonJustMove,player,skel.name)
        end
    else
        room:invalidateSkill(player, skel.name, "-phase")
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
})


skel:addEffect(fk.PreCardEffect, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data.from == player and data.card.trueName == "enemy_at_the_gates"
  end,
  on_refresh = function(self, event, target, player, data)
    local card = data.card:clone()
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = Fk.skills["gongnan__enemy_at_the_gates_skill"]
    data.card = card
  end,
})




return skel